package com.tuanzi.loan.business.service.family.impl;

import com.tuanzi.loan.business.entity.family.LoanChannelNdInfo;
import com.tuanzi.loan.business.entity.family.LoanLargeAmountPartnerControl;
import com.tuanzi.loan.business.repository.family.LoanLargeAmountPartnerControlRepository;
import com.tuanzi.loan.business.service.family.LoanLargeAmountPartnerControlService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.core.repository.JPAAuditRepository;
import com.tuanzi.loan.core.service.BaseAuditServiceImpl;
import com.tuanzi.loan.core.vo.PageSearcher;
import com.tuanzi.loan.vo.request.family.LoanLargeAmountPartnerControlSearchRequest;
import com.tuanzi.loan.vo.response.family.LoanLargeAmountPartnerControlSearchResponse;
import com.tuanzi.server.loan_base.model.db.LoanWholeSaleComment;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.retry.RetryException;
import org.springframework.retry.annotation.Retryable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Debug
@Service
@Transactional
@Retryable(value = {RetryException.class})
public class LoanLargeAmountPartnerControlServiceImpl
        extends BaseAuditServiceImpl<LoanLargeAmountPartnerControl,Long>
        implements LoanLargeAmountPartnerControlService{

    @Autowired
    LoanLargeAmountPartnerControlRepository loanLargeAmountPartnerControlRepository;

    @Override
    protected JPAAuditRepository<LoanLargeAmountPartnerControl, Long> getRepository() {
        return loanLargeAmountPartnerControlRepository;
    }

    @Override
    public Page<LoanLargeAmountPartnerControlSearchResponse> list(PageSearcher<LoanLargeAmountPartnerControlSearchRequest> pageSearcher) {
        return loanLargeAmountPartnerControlRepository.list(pageSearcher.getSearchCondition(),pageSearcher.getPageable());
    }

    @Override
    public void deleteInfoById(Long id) {
        loanLargeAmountPartnerControlRepository.delete(id);
    }

    @Override
    public String judgeCfrom(Integer type) {
         LoanWholeSaleComment loanWholeSaleComment = loanLargeAmountPartnerControlRepository.judgeCfrom(type);
         if (loanWholeSaleComment != null){
             if ("是".equals(loanWholeSaleComment.getWaitui())&&"是".equals(loanWholeSaleComment.getZhannei())){
                 return "外推 & 站内";
             }
             if ("是".equals(loanWholeSaleComment.getWaitui())){
                 return "外推";
             }

             if ("是".equals(loanWholeSaleComment.getZhannei())){
                 return "站内";
             }
         }
        return null;
    }

    @Override
    public void updateInfoById(LoanLargeAmountPartnerControlSearchRequest request) {
        loanLargeAmountPartnerControlRepository.updateById(request);
    }

    @Override
    public List<LoanWholeSaleComment> getPartnerInfo() {
        return loanLargeAmountPartnerControlRepository.getPartnerInfo();
    }

    @Override
    public List<LoanChannelNdInfo> findAllChannelN() {
        return loanLargeAmountPartnerControlRepository.findAllChannelN();
    }

}
